//
//  DDTUserAccount.swift
//  weibo
//
//  Created by mac on 16/9/25.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class DDTUserAccount: NSObject, NSCoding{
    
 /// 接口获取授权后的access token
    var access_token: String?
 /// access token 的生命周期,单位是秒数
 /// 当前授权用户的UID
    var uid: String?
    //过期时间 
    var expiresDate: NSDate?
//    access_token的生命周期
    var expires_in: NSTimeInterval = 0 {
        didSet {
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
        
    }
    
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        print("模型没有转完,\(key)")
    }
    
  override  var description: String {
        
        let keys = ["access_token", "expires_in", "uid"]
    return dictionaryWithValuesForKeys(keys).description
    }
    
    

    
    /**
    *  归档和解档
     var access_token: String?
     /// access token 的生命周期,单位是秒数
     /// 当前授权用户的UID
     var uid: String?
     //过期时间
     var expiresDate: NSDate?
     //    access_token的生命周期
     var expires_in: NSTimeInterval = 0
     
    */
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeDouble(expires_in, forKey: "expires_in")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expiresDate, forKey: "expiresDate")
    }
    
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        expires_in = aDecoder.decodeDoubleForKey("expires_in")
        super.init()
    }

}






